package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import com.ypd.shop.domain.dto.AuctionDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.AuctionItem;
import com.ypd.shop.service.IAuctionItemService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 拍卖品基础信息Controller
 * 
 * @author lin
 * @date 2025-02-28
 */

@RestController
@RequestMapping("/shop/item")
@Api(tags = "拍卖品基础信息Controller")
public class AuctionItemController extends BaseController
{
    @Autowired
    private IAuctionItemService auctionItemService;

    /**
     * 查询拍卖品基础信息列表
     */
    @ApiOperation("查询拍卖品基础信息列表")

    @GetMapping("/list")
    public TableDataInfo list(AuctionItem auctionItem)
    {
        startPage();
        List<AuctionItem> list = auctionItemService.selectAuctionItemList(auctionItem);
        return getDataTable(list);
    }

    /**
     * 管理员查询拍卖品基础信息列表
     */
    @ApiOperation("管理员查询拍卖品基础信息列表")

    @GetMapping("/listAdmin")
    public TableDataInfo listAdmin(AuctionItem auctionItem)
    {
        startPage();
        List<AuctionItem> list = auctionItemService.selectAuctionItemListByAdmin(auctionItem);
        return getDataTable(list);
    }

    /**
     * 导出拍卖品基础信息列表
     */
    @ApiOperation("导出拍卖品基础信息列表")
    @PreAuthorize("@ss.hasPermi('shop:item:export')")
    @Log(title = "拍卖品基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionItem auctionItem)
    {
        List<AuctionItem> list = auctionItemService.selectAuctionItemList(auctionItem);
        ExcelUtil<AuctionItem> util = new ExcelUtil<AuctionItem>(AuctionItem.class);
        util.exportExcel(response, list, "拍卖品基础信息数据");
    }

    /**
     * 获取拍卖品全部信息详细信息(全部)
     */
    @ApiOperation("获取拍卖品基础信息详细信息")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") String itemId)
    {
        return success(auctionItemService.selectAuctionByItemId(itemId));
    }

    /**
     * 新增拍卖品基础信息
     */
    @ApiOperation("新增拍卖品基础信息")
    @PreAuthorize("@ss.hasPermi('shop:item:add')")
    @Log(title = "拍卖品基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionDto dto)
    {
        return toAjax(auctionItemService.insertAuctionItem(dto));
    }

    /**
     * 修改拍卖品基础信息
     */
    @ApiOperation("修改拍卖品基础信息")
    @PreAuthorize("@ss.hasPermi('shop:item:edit')")
    @Log(title = "拍卖品基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionItem auctionItem)
    {
        return toAjax(auctionItemService.updateAuctionItem(auctionItem));
    }

    /**
     * 删除拍卖品基础信息
     */
    @ApiOperation("删除拍卖品基础信息")
    @PreAuthorize("@ss.hasPermi('shop:item:remove')")
    @Log(title = "拍卖品基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable String[] itemIds)
    {
        return toAjax(auctionItemService.deleteAuctionItemByItemIds(itemIds));
    }
}
